package edu.sandau.basic.vo;

import edu.sandau.basic.global.GlobalEnum;

public class BasicMsg {
    // ------------------ 原始字段 ------------------
    private GlobalEnum.OperationResult operationResult = GlobalEnum.OperationResult.UNSUCC;
    private String errorMsg = "";
    private GlobalEnum.ErrorCode errorCode = GlobalEnum.ErrorCode.UNKNOWN;

    // ------------------ Getter / Setter ------------------
    public void setErrorMsg(String errMsg) {
        this.errorMsg = errMsg;
    }

    public String getErrorMsg() {
        return this.errorMsg;
    }

    public GlobalEnum.OperationResult getOperationResult() {
        return this.operationResult;
    }

    public void setErrorCode(GlobalEnum.ErrorCode errorCode) {
        this.errorCode = errorCode;
    }

    public void setOperationResult(GlobalEnum.OperationResult operationResult) {
        this.operationResult = operationResult;
    }

    public GlobalEnum.ErrorCode getErrorCode() {
        return this.errorCode;
    }

    // ------------------ 快速返回方法 ------------------

    /**
     *  成功返回
     */
    public static BasicMsg ok(String message) {
        BasicMsg msg = new BasicMsg();
        msg.setOperationResult(GlobalEnum.OperationResult.SUCC);
        msg.setErrorCode(GlobalEnum.ErrorCode.OK);
        msg.setErrorMsg(message);
        return msg;
    }

    /**
     *  失败返回
     */
    public static BasicMsg error(String message) {
        BasicMsg msg = new BasicMsg();
        msg.setOperationResult(GlobalEnum.OperationResult.UNSUCC);
        msg.setErrorCode(GlobalEnum.ErrorCode.UNKNOWN);
        msg.setErrorMsg(message);
        return msg;
    }

    /**
     *  指定错误码的失败返回
     */
    public static BasicMsg error(GlobalEnum.ErrorCode code, String message) {
        BasicMsg msg = new BasicMsg();
        msg.setOperationResult(GlobalEnum.OperationResult.UNSUCC);
        msg.setErrorCode(code);
        msg.setErrorMsg(message);
        return msg;
    }
}
